#include "DlgUser.h"
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/msgdlg.h>
//(*InternalHeaders(DlgUser)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(DlgUser)
//*)
const wxString CDlgUser::TABLENAME=_T("user");
#define PERMIT_SUPERADMIN _T("超级管理员")
#define PERMIT_ADMIN      _T("管理员")
#define PERMIT_USER       _T("一般用户")
#define PERMIT_OTHER       _T("其他权限")
const wxString WINDOWS_TEXT = _T("用户管理模块");
//控件ID
const long CDlgUser::IDC_BTN_ADD_MOD= wxNewId();
const long CDlgUser::IDC_BTN_EXIT= wxNewId();
const long CDlgUser::IDC_BTN_SEARCH= wxNewId();
const long CDlgUser::IDC_BTN_DEL= wxNewId();
const long CDlgUser::IDC_COMBO_SEARCH= wxNewId();
const long CDlgUser::IDC_COMBO_PERMIT= wxNewId();
const long CDlgUser::IDC_EDIT_SEARCH= wxNewId();
const long CDlgUser::IDC_EDIT_ID= wxNewId();
const long CDlgUser::IDC_EDIT_PWD= wxNewId();
const long CDlgUser::IDC_EDIT_NAME= wxNewId();
const long CDlgUser::IDC_EDIT_TEL= wxNewId();
const long CDlgUser::IDC_BIRTHDAY= wxNewId();
const long CDlgUser::IDC_LIST= wxNewId();

BEGIN_EVENT_TABLE(CDlgUser,wxDialog)
    //(*EventTable(DlgUser)
    //*)
END_EVENT_TABLE()

CDlgUser::CDlgUser(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
    :m_addormod_(-1)
{
    //(*Initialize(DlgUser)
    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("id"));
    SetClientSize(wxDefaultSize);
    Move(wxDefaultPosition);
    //*)
    SetTitle(WINDOWS_TEXT);
    SetWindowStyle(GetWindowStyle()|wxRESIZE_BORDER|wxCLOSE_BOX|wxMAXIMIZE_BOX|wxMINIMIZE_BOX);
    CreateCtrlAndEvent();
    EnableAllCtrl(false);
    InitComboBoxAndListCtrl();
}

CDlgUser::~CDlgUser()
{
    //(*Destroy(DlgUser)
    //*)
}

void CDlgUser::CreateCtrlAndEvent()
{
    /////////创建控件并布局
    topSizer_=new wxBoxSizer(wxVERTICAL);//顶层窗口布局,从上到下包含每个了窗口布局
    wxBoxSizer *firSize=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *secSize=new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer *thiSize=new wxBoxSizer(wxHORIZONTAL);
    wxStaticBox *staticBox=new wxStaticBox(this,wxID_ANY,wxT("注意：双击列表数据可进行修改"));
    wxStaticBoxSizer *forSize=new wxStaticBoxSizer(staticBox,wxHORIZONTAL);
    wxBoxSizer *bottomSize=new wxBoxSizer(wxHORIZONTAL);
    topSizer_->Add(firSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(secSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(thiSize,0,wxEXPAND|wxALL,0);
    topSizer_->Add(forSize,10,wxEXPAND|wxALL,0);
    topSizer_->Add(bottomSize,0,wxEXPAND|wxALL,0);

    combo_search_=new wxChoice(this,IDC_COMBO_SEARCH);
    combo_permit_=new wxChoice(this,IDC_COMBO_PERMIT);
    btn_Add_Mod_=new wxButton(this,IDC_BTN_ADD_MOD,_T("添加"));
    btn_Del_=new wxButton(this,IDC_BTN_DEL,_T("删除"));
    btn_Exit_=new wxButton(this,IDC_BTN_EXIT,_T("退出"));
    btn_Search_=new wxButton(this,IDC_BTN_SEARCH,_T("查询"));
    text_search_=new wxTextCtrl(this,IDC_EDIT_SEARCH,wxEmptyString);
    text_id_=new wxTextCtrl(this,IDC_EDIT_ID,wxEmptyString);
    text_pwd_=new wxTextCtrl(this,IDC_EDIT_PWD,wxEmptyString);
    text_name_=new wxTextCtrl(this,IDC_EDIT_NAME,wxEmptyString);
    text_tel_=new wxTextCtrl(this,IDC_EDIT_TEL,wxEmptyString);
    time_birth_=new wxDatePickerCtrl(this,IDC_BIRTHDAY,wxDefaultDateTime,wxDefaultPosition,
                                     wxDefaultSize,wxDP_DROPDOWN|wxDP_SHOWCENTURY);
    list_=new wxListCtrl(this,IDC_LIST,wxDefaultPosition,wxDefaultSize,wxLC_REPORT|wxLC_SINGLE_SEL);

    firSize->Add(new wxStaticText(this,wxID_ANY,_T("查询类别")),1, wxTILE|wxALL|wxALIGN_RIGHT,5);
    firSize->Add(combo_search_,1, wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->Add(text_search_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    firSize->Add(btn_Search_,1,wxTILE|wxALL|wxALIGN_LEFT,5);
    secSize->Add(new wxStaticText(this,wxID_ANY,_T("账号")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    secSize->Add(text_id_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    secSize->Add(new wxStaticText(this,wxID_ANY,_T("密码")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    secSize->Add(text_pwd_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    secSize->Add(new wxStaticText(this,wxID_ANY,_T("姓名")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    secSize->Add(text_name_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("电话号码")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(text_tel_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("生日")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(time_birth_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    thiSize->Add(new wxStaticText(this,wxID_ANY,_T("权限")),1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    thiSize->Add(combo_permit_,1,wxEXPAND|wxALL|wxALIGN_CENTER,5);
    forSize->Add(list_,1,wxEXPAND | wxALL,5);
    bottomSize->Add(btn_Add_Mod_,1,wxTILE|wxALL|wxALIGN_RIGHT,5);
    bottomSize->Add(btn_Del_,1,wxTILE|wxALL|wxALIGN_CENTER,5);
    bottomSize->Add(btn_Exit_,1,wxTILE|wxALL|wxALIGN_LEFT,5);

    SetSizer(topSizer_);//绑定对话框和布局控件
    SetAutoLayout(true);
    topSizer_->Fit(this);//调用对话框大小
    topSizer_->SetSizeHints(this);//设置对话框最小大小

    ///////创建事件
    Connect(IDC_BTN_ADD_MOD,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgUser::OnBnClickedBtnAddMod);
    Connect(IDC_BTN_EXIT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgUser::OnBnClickedBtnExit);
    Connect(IDC_BTN_SEARCH,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgUser::OnBnClickedBtnSearch);
    Connect(IDC_BTN_DEL,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&CDlgUser::OnBnClickedBtnDel);
    Connect(IDC_LIST,wxEVT_COMMAND_LIST_ITEM_SELECTED,(wxObjectEventFunction)&CDlgUser::OnNMClickList);
    Connect(IDC_LIST,wxEVT_COMMAND_LIST_ITEM_ACTIVATED,(wxObjectEventFunction)&CDlgUser::OnNMDblclkList);
    wxLogDebug(_T("CreateCtrl"));
}

void CDlgUser::EnableAllCtrl( bool isEnable )
{
    if (m_addormod_==ADDMODEL) {
        FindWindowById(IDC_EDIT_ID)->Enable(isEnable);
        FindWindowById(IDC_EDIT_PWD)->Enable(isEnable);
        FindWindowById(IDC_EDIT_NAME)->Enable(isEnable);
        FindWindowById(IDC_EDIT_TEL)->Enable(isEnable);
        FindWindowById(IDC_BIRTHDAY)->Enable(isEnable);
        FindWindowById(IDC_COMBO_PERMIT)->Enable(isEnable);
        FindWindowById(IDC_COMBO_SEARCH)->Enable(isEnable);
        FindWindowById(IDC_LIST)->Enable(false);
        FindWindowById(IDC_BTN_SEARCH)->Enable(false);
        FindWindowById(IDC_EDIT_SEARCH)->Enable(false);
        FindWindowById(IDC_BTN_DEL)->Enable(false);
    } else if (m_addormod_==MODMODEL) {
        FindWindowById(IDC_EDIT_ID)->Enable(false);
        FindWindowById(IDC_EDIT_PWD)->Enable(isEnable);
        FindWindowById(IDC_EDIT_NAME)->Enable(isEnable);
        FindWindowById(IDC_EDIT_TEL)->Enable(isEnable);
        FindWindowById(IDC_BIRTHDAY)->Enable(isEnable);
        FindWindowById(IDC_COMBO_SEARCH)->Enable(isEnable);
        FindWindowById(IDC_COMBO_PERMIT)->Enable(isEnable);
        FindWindowById(IDC_LIST)->Enable(false);
        FindWindowById(IDC_BTN_SEARCH)->Enable(false);
        FindWindowById(IDC_EDIT_SEARCH)->Enable(false);
        FindWindowById(IDC_BTN_DEL)->Enable(false);
    } else {
        FindWindowById(IDC_EDIT_ID)->Enable(isEnable);
        FindWindowById(IDC_EDIT_PWD)->Enable(isEnable);
        FindWindowById(IDC_EDIT_NAME)->Enable(isEnable);
        FindWindowById(IDC_EDIT_TEL)->Enable(isEnable);
        FindWindowById(IDC_BIRTHDAY)->Enable(isEnable);
        FindWindowById(IDC_COMBO_PERMIT)->Enable(isEnable);
        FindWindowById(IDC_COMBO_SEARCH)->Enable(true);
        FindWindowById(IDC_LIST)->Enable(true);
        FindWindowById(IDC_BTN_SEARCH)->Enable(true);
        FindWindowById(IDC_EDIT_SEARCH)->Enable(true);
        FindWindowById(IDC_BTN_DEL)->Enable(true);
    }
    wxLogDebug(_T("EnableAllCtrl"));
}

void CDlgUser::InitComboBoxAndListCtrl()
{
    wxChoice *pchoice=wxDynamicCast(FindWindowById(IDC_COMBO_SEARCH),wxChoice);
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    pList->SetSingleStyle(wxLC_REPORT);
    pList->SetSingleStyle(wxLC_SINGLE_SEL);
    const vector<pair<wxString,wxString> >&chs_fileds_name=GetFiled_CHS_Name(_T("name_user"));
    auto it=chs_fileds_name.cbegin();
    for (; it!=chs_fileds_name.cend(); ++it) {
        wxLogDebug(_T("%s "),it->first);
        pchoice->Append(it->first);
        pList->InsertColumn(pList->GetColumnCount(),it->first,wxLIST_FORMAT_LEFT,wxLIST_AUTOSIZE);
    }
    pchoice->Refresh();
    pList->Refresh();
    pchoice=wxDynamicCast(FindWindowById(IDC_COMBO_PERMIT),wxChoice);
    pchoice->Append(PERMIT_SUPERADMIN);
    pchoice->Append(PERMIT_ADMIN);
    pchoice->Append(PERMIT_USER);
    pchoice->Append(PERMIT_OTHER);
    pchoice->Refresh();
    wxLogDebug(_T("InitComboBoxAndListCtrl"));
}


void CDlgUser::OnBnClickedBtnSearch(wxCommandEvent& event)
{
    wxBusyCursor waticursor;
    wxChoice *pBox=wxDynamicCast(FindWindowById(IDC_COMBO_SEARCH),wxChoice);
    int index=pBox->GetSelection();
    wxString strComboTextFirst,strComboTextSecond;
    if (index == wxNOT_FOUND) {
//        wxLogDebug(_T("查询类别不能为空"));
//        return;
    } else {
        strComboTextFirst=pBox->GetString(index);
    }
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    const vector<pair<wxString,wxString> >&chs_filed_name=GetFiled_CHS_Name(_T("name_user"));
    if (chs_filed_name.empty()) {
        return;
    }
    vector<pair<wxString,int> >fileds;
    map<wxString,wxString> condition;
    map<wxString,wxString>*pcondit=NULL;
    auto it=chs_filed_name.cbegin();
    for (; it!=chs_filed_name.cend(); ++it) {
        if (strComboTextFirst==it->first) {
            strComboTextSecond=it->second;
        }
        fileds.push_back(std::make_pair(it->second,(int)FILED_TEXT));
    }
    wxTextCtrl *pText=wxDynamicCast(FindWindowById(IDC_EDIT_SEARCH),wxTextCtrl);
    wxString csEditText=pText->GetValue();
    csEditText.Trim(true);
    csEditText.Trim(false);
    if (!csEditText.IsEmpty() && !strComboTextFirst.IsEmpty()) {
        condition[strComboTextSecond]=csEditText;
        pcondit=&condition;
    }
    SelFromDb(fileds,TABLENAME,pcondit,wxEmptyString,pList);
    wxLogDebug(_T("OnBnClickedBtnSearch"));
}
void CDlgUser::OnBnClickedBtnDel(wxCommandEvent& event)
{
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    long selitemIndex=-1;
    selitemIndex=pList->GetNextItem(selitemIndex,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);//得到选中的行数
    if (selitemIndex ==-1) {
        return;
    }
    wxString csid=pList->GetItemText(selitemIndex,0);
    wxString csname=pList->GetItemText(selitemIndex,1);
    wxString tip=_T("确实要删除账号为[")+csid+_T("]的用户吗？");
    if(wxNO==wxMessageBox(tip,_T("删除确认"),wxYES_NO)) {
        return;
    }
    map<wxString,wxString> condition;
    condition[_T("userid")]=m_keyvalue_;
    if(DelFromDb(TABLENAME,&condition)) {
        wxMessageBox(_T("删除完成"),_T("删除完成"),wxOK);
        pList->DeleteItem(selitemIndex);
    } else {
        wxMessageBox(sqlite3_errmsg(g_db),_T("删除出错"));
        return;
    }
    wxLogDebug(_T("OnBnClickedBtnDel"));
}
void CDlgUser::OnBnClickedBtnExit(wxCommandEvent& event)
{
    if (ADDMODEL==m_addormod_ || MODMODEL==m_addormod_) {
        m_addormod_=-1;
        EnableAllCtrl(false);
        wxButton *pbtn=wxDynamicCast(FindWindowById(IDC_BTN_ADD_MOD),wxButton);
        pbtn->SetLabel(_T("添加"));
        pbtn=wxDynamicCast(FindWindowById(IDC_BTN_EXIT),wxButton);
        pbtn->SetLabel(_T("退出"));
        SetLabel(WINDOWS_TEXT);
    } else {
        Close();
    }
    wxLogDebug(_T("OnBnClickedBtnExit"));
}
void CDlgUser::OnBnClickedBtnAddMod(wxCommandEvent& event)
{
    wxString sql;
    if(ADDMODEL ==m_addormod_ || MODMODEL ==m_addormod_) {
        wxTextCtrl *pText=wxDynamicCast(FindWindowById(IDC_EDIT_ID),wxTextCtrl);
        wxString csTypeName=pText->GetValue();
        if(csTypeName.IsEmpty()) {
            wxMessageBox(_T("用户账号不能为空"),_T("错误"),wxOK);
            return;
        }
        pText=wxDynamicCast(FindWindowById(IDC_EDIT_ID),wxTextCtrl);
        csTypeName=pText->GetValue();
        if(csTypeName.IsEmpty()) {
            wxMessageBox(_T("用户姓名不能为空"),_T("错误"),wxOK);
            return;
        }
        int permit;
        int nIdx;//行索引
        wxDatePickerCtrl *pDT=wxDynamicCast(FindWindowById(IDC_BIRTHDAY),wxDatePickerCtrl);
        wxDateTime time_birthday=pDT->GetValue();
        wxString csuserID,csuserpwd,csusername,csusertel,csTemp;
        pText=wxDynamicCast(FindWindowById(IDC_EDIT_ID),wxTextCtrl);
        csuserID=pText->GetValue();
        pText=wxDynamicCast(FindWindowById(IDC_EDIT_PWD),wxTextCtrl);
        csuserpwd=pText->GetValue();
        pText=wxDynamicCast(FindWindowById(IDC_EDIT_NAME),wxTextCtrl);
        csusername=pText->GetValue();
        pText=wxDynamicCast(FindWindowById(IDC_EDIT_TEL),wxTextCtrl);
        csusertel=pText->GetValue();
        wxChoice* pBox=wxDynamicCast(FindWindowById(IDC_COMBO_PERMIT),wxChoice);
        csTemp=pBox->GetStringSelection();
        wxLogDebug(_T("permit=%s"),csTemp);
        ///1表超级管理员2表管理员3表一般用户
        if (csTemp.CmpNoCase(PERMIT_SUPERADMIN)==0) {
            permit=1;
        } else if (csTemp.CmpNoCase(PERMIT_ADMIN)==0) {
            permit=2;
        } else if(csTemp.CmpNoCase(PERMIT_USER)==0) {
            permit=3;
        } else {
            permit=0;
        }
        wxListCtrl* pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
        if (ADDMODEL==m_addormod_) { //由添加转为完成
            //添加新记录
            map<wxString,wxString> fileds;
            fileds[_T("userid")]=csuserID;
            fileds[_T("userName")]=csusername;
            fileds[_T("userPWD")]=csuserpwd;
            fileds[_T("userTel")]=csusertel;
            fileds[_T("userBirthday")]=time_birthday.FormatISODate();
            fileds[_T("userPermit")]=wxString::Format(_T("%d"),permit);
            if(!AddIntoDb(fileds,TABLENAME)) {
                wxMessageBox(sqlite3_errmsg(g_db),_T("添加出错"));
                return;
            }
            m_addormod_=-1;
            EnableAllCtrl(false);
            wxButton *pbtn=wxDynamicCast(FindWindowById(IDC_BTN_ADD_MOD),wxButton);
            pbtn->SetLabel(_T("添加"));
            pbtn=wxDynamicCast(FindWindowById(IDC_BTN_EXIT),wxButton);
            pbtn->SetLabel(_T("退出"));
            SetLabel(WINDOWS_TEXT);

            //成功把该行插入到list控件中
            pList->InsertItem(pList->GetItemCount(),_T(""));
            nIdx=pList->GetItemCount()-1;
        } else if (MODMODEL==m_addormod_) { //由修改转为完成
            map<wxString,wxString> fileds,condition;
            fileds[_T("userName")]=csusername;
            fileds[_T("userPWD")]=csuserpwd;
            fileds[_T("userTel")]=csusertel;
            fileds[_T("userBirthday")]=time_birthday.FormatISODate();
            fileds[_T("userPermit")]=wxString::Format(_T("%d"),permit);
            condition[_T("userid")]=csuserID;
            if(!ModToDb(fileds,TABLENAME,&condition)) {
                wxMessageBox(sqlite3_errmsg(g_db),_T("修改出错"));
                return;
            }
            m_addormod_=-1;
            EnableAllCtrl(false);
            wxButton *pbtn=wxDynamicCast(FindWindowById(IDC_BTN_ADD_MOD),wxButton);
            pbtn->SetLabel(_T("添加"));
            pbtn=wxDynamicCast(FindWindowById(IDC_BTN_EXIT),wxButton);
            pbtn->SetLabel(_T("退出"));
            SetLabel(WINDOWS_TEXT);
            //成功把修改结果反应到list控件中
            nIdx=-1;
            nIdx = pList->GetNextItem(nIdx,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
            if(nIdx == -1) {
                return;
            }
        }
        pList->SetItem(nIdx,0,csuserID);
        pList->SetItem(nIdx,1,csuserpwd);
        pList->SetItem(nIdx,2,csusername);
        pList->SetItem(nIdx,3,csusertel);
        pList->SetItem(nIdx,4,time_birthday.FormatISODate());
        pList->SetItem(nIdx,5,wxString::Format(_T("%d"),permit));
    } else {
        m_addormod_=ADDMODEL;
        EnableAllCtrl(true);
        wxButton *pbtn=wxDynamicCast(FindWindowById(IDC_BTN_ADD_MOD),wxButton);
        pbtn->SetLabel(_T("完成"));
        pbtn=wxDynamicCast(FindWindowById(IDC_BTN_EXIT),wxButton);
        pbtn->SetLabel(_T("取消添加"));
        SetLabel(WINDOWS_TEXT+_T("_添加"));
        wxTextCtrl *pText=wxDynamicCast(FindWindowById(IDC_EDIT_NAME),wxTextCtrl);
        pText->SetLabel(_T(""));
    }
    wxLogDebug(_T("OnBnClickedBtnAddMod"));
}
void CDlgUser::OnNMClickList(wxListEvent& event)
{
    if(event.GetIndex()==-1) {
        return;
    }
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    m_keyvalue_=pList->GetItemText(event.GetIndex(),0);//得到主键值
    wxTextCtrl *pText=wxDynamicCast(FindWindowById(IDC_EDIT_ID),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),0));
    pText=wxDynamicCast(FindWindowById(IDC_EDIT_PWD),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),1));
    pText=wxDynamicCast(FindWindowById(IDC_EDIT_NAME),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),2));
    pText=wxDynamicCast(FindWindowById(IDC_EDIT_TEL),wxTextCtrl);
    pText->SetValue(pList->GetItemText(event.GetIndex(),3));
    wxDateTime bir;
    if(bir.ParseDate(pList->GetItemText(event.GetIndex(),4))) {
        wxDatePickerCtrl *pDT=wxDynamicCast(FindWindowById(IDC_BIRTHDAY),wxDatePickerCtrl);
        pDT->SetValue(bir);
    }
    ///1开头表收支类别 2开头表菜式类别
    wxString strTmp=pList->GetItemText(event.GetIndex(),5);
    wxChoice *pBox=wxDynamicCast(FindWindowById(IDC_COMBO_PERMIT),wxChoice);
    if (strTmp.Left(1)==_T("1")) {
        pBox->SetStringSelection(PERMIT_SUPERADMIN);
    } else if (strTmp.Left(1)==_T("2")) {
        pBox->SetStringSelection(PERMIT_ADMIN);
    } else if (strTmp.Left(1)==_T("3")) {
        pBox->SetStringSelection(PERMIT_USER);
    } else {
        pBox->SetStringSelection(PERMIT_OTHER);
    }
    wxLogDebug(_T("OnNMClickList"));
}
void CDlgUser::OnNMDblclkList(wxListEvent& event)
{
    if(event.GetIndex()==-1) {
        return;
    }
    wxListCtrl *pList=wxDynamicCast(FindWindowById(IDC_LIST),wxListCtrl);
    m_keyvalue_=pList->GetItemText(event.GetIndex(),0);//得到主键值
    m_addormod_=MODMODEL;
    EnableAllCtrl(true);
    wxButton *pbtn=wxDynamicCast(FindWindowById(IDC_BTN_ADD_MOD),wxButton);
    pbtn->SetLabel(_T("保存"));//修改完回到待增加状态
    pbtn=wxDynamicCast(FindWindowById(IDC_BTN_EXIT),wxButton);
    pbtn->SetLabel(_T("取消修改"));
    wxString text=WINDOWS_TEXT+_T("_修改");
    SetLabel(text);
    wxLogDebug(_T("OnNMDblclkList"));
}

